package com.bl.student.dao.repository;

import com.bl.student.dao.model.custom.ArenaSummaryEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

/**
 * Created by yujingyi on 2018/3/28.
 */
public interface ArenaSummaryRepository extends JpaRepository<ArenaSummaryEntity, String> {
    @Query(value = "SELECT a.id as id, d.id as detailId, d.collect as collect, a.weight as weight FROM ARENA a LEFT JOIN DETAIL d ON d.ID = a.DETAIL_ID " +
            "WHERE a.START_TIME = ?1 AND a.TYPE = ?2 AND a.status = ?3 /*#pageable*/ ORDER BY d.collect DESC",
            countQuery = "SELECT COUNT(*) FROM ARENA a LEFT JOIN DETAIL d ON d.ID = a.DETAIL_ID " +
                    "WHERE a.START_TIME = ?1 AND a.TYPE = ?2 AND a.status = ?3",
            nativeQuery = true)
    Page<ArenaSummaryEntity> findByStatusAndStartTimeAndTypeOrderByCollect(String startTime, String arenaType, String onlineStatus, Pageable pageable);
}
